package com.example.designpattern.test.testProtected.test;

public class Main4 {
    public static void main(String[] args) {
//        System.out.println(/*f(3)+*/"\n" + f2(6));
//        System.out.println(f3(5, 2));
//        System.out.println(f4(10, 3));
//        System.out.println(f5("你好",5));
        System.out.println(f6(2));
    }

    public static int f(int n) {
        int i;
        if (n == 1) {
            return 1;
        } else
            return i = n * f(n - 1);
    }

    public static int f2(int n) {
        int i;
        if (n == 1 || n == 0) {
            return 1;
        } else
            return i = n + f2(n - 2);
    }

    public static int f3(int n, int d0) {
        if (n == d0) {
            return d0;
        } else {
            return f3(n - 1, d0) + n;
        }
    }

    //计算m的n次方
    public static int f4(int m, int n) {
        if (n == 1)
            return m;
        else
            return m * f4(m, n - 1);
    }

    public static String f5(String s,int count){
        if (count==1)
            return s;
        else{
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("("+f5(s,count-1)+")");
            return "("+f5(s,count-1)+")";

        }
    }

    public static String f6(int n){
        if (n == 1) {
            return "1";
        }else {
            return n+""+f(n-1)+"";
        }
    }
}
